#include <vector>

namespace ssy
{

	template<typename T>
	class Less
	{
	public:
		bool operator() (const T& a, const T& b)
		{
			return a < b;
		}
	};


	template<typename T>
	class Great
	{
	public:
		bool operator() (const T& a, const T& b)
		{
			return a > b;
		}
	};

	template<typename T, typename Container = std::vector<T>, typename Compare = Less<T>>
	class priority_queue
	{
	public:

		void push(const T& x)
		{
			_con.push_back(x);

			adjust_up(_con.size() - 1);
		}
		void pop()
		{
			swap(_con[0], _con[_con.size() - 1]);
			_con.pop_back();

			adjust_down(0, _con.size());
		}

		void adjust_down(int pos)
		{
			int parent = pos;
			int child = parent * 2 + 1;

			Compare cmp;

			while (child < _con.size())
			{
				//if (child + 1 < _con.size() && _con[child] < _con[child + 1])
				if (child + 1 < _con.size() && cmp(_con[child], _con[child + 1]))
					++child;

				if (cmp(_con[parent] , _con[child]))
				{
					std::swap(_con[parent], _con[child]);
					parent = child;
					child = parent * 2 + 1;
				}
				else
				{
					break;
				}
			}
		}
		void adjust_up(int pos)
		{
			int child = pos;
			int parent = (child - 1) / 2;

			Compare cmp;

			while (child > 0)
			{
				if (cmp(_con[parent] , _con[child]))
				{
					std::swap(_con[parent], _con[child]);

					child = parent;
					parent = (child - 1) / 2;

				}
				else
				{
					break;
				}
			}
		}

		size_t size()
		{
			return _con.size();
		}

		bool empty()
		{
			return _con.empty;
		}

		T top()
		{
			return _con.front();
		}
	private:
		Container _con;
	};

	
}